home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / spmate13.zip / SPELMATE.BA$ / spelmate.bas
BASIC Source File  |  1993-11-18  |  5KB  |  147 lines

  1. Option Explicit
  2.  
  3. ' ++++++++++++++++++++++++++++++++++++++++++++++++++++++
  4. '                                                      +
  5. ' SpelChek.BAS.   (c) A.McMonnies/MEDC, 1993.          +
  6. ' +++++++++++++++++++++++++++++++++++++++++++          +
  7. ' This is a small library demonstrating the use of the +
  8. ' seriously cool SPELLMATE spell checker library       +
  9. ' from James Heron's Acrian Software Products.         +
  10. ' It includes Visual Basic declarations of the SPELMATE+
  11. ' library functions, a declaration for IsCharAlpha from+
  12. ' the Windows User.DLL library (very useful) and some  +
  13. ' small functions which help to parse strings of text  +
  14. ' for spell checking.                                  +
  15. ' The module can be used to do a simple parse of       +
  16. ' strings of text, or to include a spell check.        +
  17. ' To check spelling, call SetSpellOn from your program +
  18. ' (which should incorporate this module in the Project +
  19. ' file), and then call DoSpellCheck(), passing the     +
  20. ' string to be examined as a parameter.  e.g......               +
  21. '                                                      +
  22. '   Dim s$                                             +
  23. '      s$ = "Check the spelling of the word speling."  +
  24. '      SetSpellOn                                      +
  25. '      Parse(s$)                                       +
  26. '                                                      +
  27. ' If you do not need to check spelling, do not use     +
  28. ' SetSpellOn, or call SetSpellOff to disable checking. +
  29. '+++++++++++++++++++++++++++++++++++++++++++++++++++++++
  30.  
  31. ' Alphanumeric id function...
  32. Declare Function IsCharAlpha% Lib "User" (ByVal cChar%)
  33.  
  34. ' Spellmate functions...
  35. Declare Function SpelMateInit Lib "spelmate.dll" () As Integer
  36. Declare Function SpellCheck Lib "spelmate.dll" (ByVal AWord As String) As Integer
  37. Declare Function AddWord Lib "spelmate.dll" (ByVal AWord As String) As Integer
  38. Declare Sub IgnoreWord Lib "spelmate.dll" (ByVal AWord As String)
  39. Declare Sub SuggestVBWord Lib "spelmate.dll" (ByVal AWord As String)
  40. Declare Sub SuggestModalVBWord Lib "spelmate.dll" (ByVal AHandle As Integer, ByVal AWord As String)
  41.  
  42. Sub DoSpellCheck (T As TextBox)
  43. ' Reduce input text to a list of unique text strings
  44. ' and check the spelling of each.
  45. Dim Wd$, W As String * 20, ok%, ip%
  46. Dim Start%
  47.     ok% = SpelMateInit()
  48.     If Not ok% Then
  49.         MsgBox "Spellmate has not initialised.", 0, "Spell Check"
  50.         Exit Sub
  51.     End If
  52.     If Len((T.Text)) > 0 Then
  53.         Start% = T.SelStart
  54.     Else
  55.         Exit Sub
  56.         MsgBox "No text to check.", 0, "Spell Check"
  57.     End If
  58.     Do
  59.         Wd$ = Trim$(GetWord$((T.Text), Start%))
  60.         If Wd$ = "" Then
  61.             T.SelLength = 0
  62.             T.SelStart = Len((T.Text))
  63.             Exit Do  ' No more words.
  64.         Else
  65.             ' Set select area to highlight word...
  66.             T.SetFocus
  67.             T.SelStart = Start% - 1
  68.             T.SelLength = Len(Wd$)
  69.             ' Now check it's spelling...
  70.             W = Wd$ & Chr$(0)
  71.             ok% = SpellCheck(Wd$)
  72.             If ok% = 0 Then
  73.                 SuggestModalVBWord Form1.hWnd, W
  74.                 If Asc(Left$(W, 1)) = 0 Then
  75.                     Exit Do  ' A NULL
  76.                 End If
  77.                 ip% = InStr(W, Chr$(0))
  78.                 If (ip% > 0) And (Wd$ <> Left$(W, ip% - 1)) Then
  79.                     Wd$ = Left$(W, ip% - 1)
  80.                     T.SelText = Wd$
  81.                 End If
  82.             End If
  83.         Start% = Start% + Len(Wd$)
  84.         End If
  85.     Loop
  86. End Sub
  87.  
  88. Function GetWord$ (InText$, StartPos%)
  89. ' Function returns the next word in InText$, starting at
  90. ' StartPos%, or "" if StartPos% is past last word.
  91. Dim L%, WdLen%, c As String * 1, FinPos%
  92.     L% = Len(InText$)
  93.     ' Is InText$ empty, or is StartPos% past it's end?
  94.     If L% = 0 Or StartPos% > L% Then
  95.         GetWord$ = ""
  96.         Exit Function
  97.     End If
  98.  
  99.     ' Find the start of the next word...
  100.     If StartPos% < 1 Then
  101.         StartPos% = 1
  102.     End If
  103.     Do Until IsCharAlpha%(Asc(Mid$(InText$, StartPos%, 1)))
  104.         StartPos% = StartPos% + 1
  105.         ' Check we've not overrun the end of Intext$...
  106.         If StartPos% > L% Then
  107.             GetWord$ = ""
  108.             Exit Function
  109.         End If
  110.     Loop
  111.  
  112.     ' We're at the start, find the end...
  113.     FinPos% = StartPos% + 1
  114.     Do While FinPos% <= L%
  115.         If IsWordChar%(Mid$(InText$, FinPos%, 1)) Then
  116.             FinPos% = FinPos% + 1
  117.         Else
  118.             Exit Do
  119.         End If
  120.     Loop
  121.     ' Adjust for a possessive single quote...
  122.     If Mid$(InText, FinPos% - 1, 1) = "'" Then
  123.         FinPos% = FinPos% - 1
  124.     End If
  125.     WdLen% = FinPos% - StartPos%
  126.  
  127.     ' Now extract the word...
  128.     GetWord$ = Trim$(Mid$(InText$, StartPos%, WdLen%))
  129.     ' StartPos% = FinPos% + 1
  130. End Function
  131.  
  132. Function IsWordChar% (c$)
  133. Dim r%
  134.     r% = IsCharAlpha%(Asc(c$))
  135.     If r% Then
  136.         IsWordChar% = True
  137.         Exit Function
  138.     Else
  139.         If c$ = "'" Then
  140.             IsWordChar% = True
  141.             Exit Function
  142.         End If
  143.     End If
  144.     IsWordChar% = r%
  145. End Function
  146.  
  147.